<?php

namespace App\Kuafu\WaiMai\Validate;

use App\Kuafu\Base\Validate\BaseValidate;
use App\Kuafu\WaiMai\Enum\WaiMaiCodeEnum;
use App\Kuafu\WaiMai\Exceptions\WaiMaiException;

class WaiMaiValidate extends BaseValidate
{
    public static function finishSwitch(array $data)
    {
        $rules = [
            'switch'         => ['required', 'integer', 'between:0,1'],
            'reservePrepare' => ['required', 'int', 'between:1, 86400'],
            'reserveFinish'  => ['required', 'int', 'between:1, 86400'],
        ];

        $messages = [];

        $valid = self::validateCheck($data, $rules, $messages);
        if ($valid) {
            throw new WaiMaiException(WaiMaiCodeEnum::ERR_SET_CONFIG_VALID, $valid);
        }
    }

    public static function timeConfig(array $data)
    {
        $rules = [
            'timeType'     => ['required', 'integer', 'between:1,3'],
            'timeStart'    => ['required', 'string', 'date_format:H:i:s'],
            'timeEnd'      => ['required', 'string', 'date_format:H:i:s'],
            'finishConfig' => ['required', 'array'],
        ];

        $messages = [];

        $valid = self::validateCheck($data, $rules, $messages);
        if ($valid) {
            throw new WaiMaiException(WaiMaiCodeEnum::ERR_SET_CONFIG_VALID, $valid);
        }
    }

    public static function finishConfig(array $data)
    {
        $rules = [
            'priceType' => ['required', 'integer', 'between:1,3'],
            'seconds'   => ['required', 'integer', 'between:1,100000'],
        ];

        $messages = [];

        $valid = self::validateCheck($data, $rules, $messages);
        if ($valid) {
            throw new WaiMaiException(WaiMaiCodeEnum::ERR_SET_CONFIG_VALID, $valid);
        }
    }

    public static function delayPush(array $data)
    {
        $rules = [
            'orderId' => ['required'],
            'seconds' => ['required', 'integer', 'between:30, 1800'],
        ];

        $messages = [];

        $valid = self::validateCheck($data, $rules, $messages);
        if ($valid) {
            throw new WaiMaiException(WaiMaiCodeEnum::ERR_SET_CONFIG_VALID, $valid);
        }
    }
}
